package it.polito.connectedcar.tcc;

import java.awt.geom.Point2D;

/**
 * This class models a TrafficLight phase change representation for a TCC.This
 * is a middle layer class used to extract the information potentially needed by
 * a vehicle and used by a TCC to send TL information to a vehicle. <br/>
 * A Traffic light phase change is described by the TL position , the current
 * phase index with respect to its whole program , the next phase switch time
 * and the current and next state expressed in Red-yellow-green colors strings
 * 
 * @author Nicola Aresta
 * 
 */
public class TCCTrafficLightPhaseChange {

	private String currentState;
	private String nextState;
	private long lastChangeTimeStamp;
	private long assumedTimeToExchange;
	private Point2D position;

	public String getCurrentState() {
		return currentState;
	}

	public void setCurrentState(String currentState) {
		this.currentState = currentState;
	}

	public String getNextState() {
		return nextState;
	}

	public void setNextState(String nextState) {
		this.nextState = nextState;
	}

	public long getAssumedTimeToExchange() {
		return assumedTimeToExchange;
	}

	public void setAssumedTimeToSwitch(long assumedTimeToExchange) {
		this.assumedTimeToExchange = assumedTimeToExchange;
	}

	public Point2D getPosition() {
		return position;
	}

	public void setPosition(Point2D position) {
		this.position = position;
	}

	public long getLastChangeTimeStamp() {
		return lastChangeTimeStamp;
	}

	public void setLastChangeTimeStamp(long lastChangeTimeStamp) {
		this.lastChangeTimeStamp = lastChangeTimeStamp;
	}

	public enum TRAFFICLIGHT_STATE {
		RED("r"), GREEN("g"), YELLOW("y");

		private final String state;

		TRAFFICLIGHT_STATE(String state) {
			this.state = state;
		}

		public String getState() {
			return this.state;
		}

		public static TRAFFICLIGHT_STATE fromState(String state)throws Exception {
			for (TRAFFICLIGHT_STATE tState : TRAFFICLIGHT_STATE.values()) {
				if (tState.getState().equalsIgnoreCase(state))
					return tState;
			}
			throw new Exception("illegal traffic light state");
		}
	}
}
